<%@ Page Language="C#" MasterPageFile="~/MasterDefault.master" AutoEventWireup="true"
    Inherits="TeamTime.StaffMembersForm" Title="TeamTime Management System - Staff Members"
    StylesheetTheme="Default" CodeBehind="StaffMembersForm.aspx.cs" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register Src="LabelWithTimedMsg.ascx" TagName="LabelWithTimedMsg" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:ScriptManager runat="server" ID="ScriptManager1" EnablePartialRendering="true">
        <Services>
            <asp:ServiceReference Path="AutoComplete.asmx" />
        </Services>
    </asp:ScriptManager>
    <clib:UpdatePanelExtender runat="server" ID="UpdatePanelExtender1" UpdateMode="Conditional">
        <ContentTemplate>
            <br />
            <h3>
                Staff Members &nbsp; &nbsp;<asp:Button runat="server" ID="btnAddNew" Text="Add a new staff member"
                    OnClick="btnAddNew_Click" CausesValidation="False" />
            </h3>
            <hr />
            <asp:Button runat="server" ID="btnAddDummy" Text="Add New" Visible="true" Style="display: none;" />
            <clib:ModalPopupPanel runat="server" ID="popUp1" TargetControlID="btnAddDummy" Width="500"
                Title="Staff Member">
                <asp:Panel runat="server" ID="pnlAdd" SkinID="PopupPanel" DefaultButton="btnSave">
                    <table cellspacing="0">
                        <tr id="trID" runat="server" visible="false">
                            <td>
                                ID
                            </td>
                            <td>
                                <asp:TextBox ID="txtID" runat="server" ReadOnly="true" BackColor="#E0E0E0" BorderStyle="None"></asp:TextBox>&nbsp;
                                <asp:LinkButton ID="lnkLoadDup" runat="server" OnClick="lnkLoadDup_Click" Visible="False"
                                    CausesValidation="false">
                                This record already exists.  Click to Load.</asp:LinkButton>
                            </td>
                            <td>
                                &nbsp;
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Person
                            </td>
                            <td>

                                <asp:TextBox ID="txtPersonName" runat="server" Width="300px"></asp:TextBox>
                                <ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoCompleteExtender1" TargetControlID="txtPersonName"
                                    ServicePath="AutoComplete.asmx" ServiceMethod="getPersons" MinimumPrefixLength="1"
                                    EnableCaching="true" OnClientPopulating='show99' OnClientPopulated='hide99' SkinID="AutoCompleteExtender" 
                                     />
                                <asp:RequiredFieldValidator ID="reqValPersonName" runat="server" ControlToValidate="txtPersonName"
                                    Display="Dynamic" ErrorMessage="* Required" ValidationGroup="popup2"></asp:RequiredFieldValidator>
                                <img id="img99" src="App_Themes/Default/Images/ajaxloader.gif" alt="prog" style="visibility: hidden;" />

                                <script type="text/javascript">
                                    function show99() {
                                        var ctrlid = 'img99';
                                        document.getElementById(ctrlid).style.visibility = 'visible';
                                    }
                                    function hide99() {
                                        var ctrlid = 'img99';
                                        document.getElementById(ctrlid).style.visibility = 'hidden';
                                    }
                                </script>

                            </td>
                        </tr>
                        <tr>
                            <td>
                                Office
                            </td>
                            <td>
                                <asp:DropDownList ID="ddlOfficeID" runat="server" Enabled="false">
                                    <%-- TODO: Make autocomplete --%>
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Designation
                            </td>
                            <td>
                                <asp:DropDownList ID="ddlDesignationID" runat="server" Enabled="false">
                                </asp:DropDownList>
                                <%-- <asp:TextBox ID="txtDesignation" runat="server"></asp:TextBox>
                                &nbsp;<asp:RequiredFieldValidator ID="reqValDesignation" runat="server" Display="Dynamic"
                                    ErrorMessage="* Required" ValidationGroup="popup" ControlToValidate="txtDesignation"></asp:RequiredFieldValidator>--%>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Needs Business Cards
                            </td>
                            <td>
                                <asp:CheckBox ID="chkNeedsBusinessCards" runat="server" readonly="true"></asp:CheckBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Start Date
                            </td>
                            <td>
                                <clib:TextBoxCalendar ID="calStartDate" runat="server" EnableViewState="true" ClearText=""
                                    ValidationGroup="popup" Required="true" ErrorMessage="* Required">
                                </clib:TextBoxCalendar>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                End Date
                            </td>
                            <td>
                                <clib:TextBoxCalendar ID="calEndDate" runat="server" EnableViewState="true" ClearText="">
                                </clib:TextBoxCalendar>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" align="center">
                                <asp:Button ID="btnSave" runat="server" Text="Save" ValidationGroup="popup" OnClick="btnSave_Click" />
                                <uc1:LabelWithTimedMsg ID="lblSaveMessage" runat="server" />
                            </td>
                        </tr>
                        <tr id="trModif" runat="server" visible="true">
                            <td colspan="3">
                                Modified By&nbsp;
                                <asp:TextBox ID="txtUserNameModifiedBy" runat="server" Width="137px" MaxLength="4"
                                    ReadOnly="true" BackColor="#E0E0E0" BorderStyle="None"></asp:TextBox>
                                On
                                <asp:TextBox ID="txtRecordDate" runat="server" Width="62px" MaxLength="10" ReadOnly="true"
                                    BackColor="#E0E0E0" BorderStyle="None"></asp:TextBox>&nbsp;
                            </td>
                        </tr>
                    </table>
                </asp:Panel>
            </clib:ModalPopupPanel>
            <table id="tblHead" cellspacing="0" cellpadding="1" border="0" runat="server">
                <tr>
                    <td>
                        Search for&nbsp;
                    </td>
                    <td colspan="3">
                        <asp:TextBox ID="txtSearchFor" runat="server" MaxLength="100" Width="200px"></asp:TextBox>
                        <asp:Button ID="btnSearch" runat="server" Text="Search >>" CausesValidation="False"
                            OnClick="btnSearch_Click"></asp:Button>
                    </td>
                </tr>
            </table>
            <br />
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" SkinID="GridView"
                AllowPaging="True" PageSize="20" AllowSorting="True" DataKeyNames="ID" OnPageIndexChanging="GridView1_PageIndexChanging"
                OnRowCommand="GridView1_RowCommand" OnRowDeleting="GridView1_RowDeleting" 
                EnableSortingAndPagingCallbacks="True" onsorting="GridView1_Sorting">
                <Columns>
                    <asp:TemplateField HeaderText="" SortExpression="ID">
                        <ItemTemplate>
                            <asp:LinkButton ID="lnkID" runat="server" CausesValidation="false" CommandName="Select"
                                Text="Edit" CommandArgument='<%# DataBinder.Eval(Container, "DataItem.ID") %>'></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="FullName" HeaderText="Name" SortExpression="FullName">
                    </asp:BoundField>
                    <asp:BoundField DataField="Office" HeaderText="Office" SortExpression="Office"></asp:BoundField>
                    <%--<asp:BoundField DataField="Province" HeaderText="Province" SortExpression="Province">
                    </asp:BoundField>--%>
                    <asp:BoundField DataField="Designation" HeaderText="Designation" SortExpression="Designation">
                    </asp:BoundField>
                    <asp:TemplateField HeaderText="Email" SortExpression="Email">
                        <ItemTemplate>
                            <asp:HyperLink ID="hypEmail" runat="server" NavigateUrl='<%# "mailto:" + DataBinder.Eval(Container, "DataItem.Email") %>'
                                Text='<%# DataBinder.Eval(Container, "DataItem.Email") %>'><%# DataBinder.Eval(Container, "DataItem.Email") %></asp:HyperLink>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="TelWork" HeaderText="Tel" SortExpression="TelWork"></asp:BoundField>
                    <asp:BoundField DataField="TelCell" HeaderText="Cell" SortExpression="TelCell"></asp:BoundField>
                    <asp:BoundField DataField="NeedsBusinessCards" HeaderText="Needs Bus. Cards" SortExpression="NeedsBusinessCards" Visible="false"></asp:BoundField>
                    <asp:BoundField DataField="RecordDate" HeaderText="Record Date" DataFormatString="{0:yyyy/MM/dd}" Visible="False"></asp:BoundField>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:LinkButton runat="server" CausesValidation="false" CommandName="Delete" Text="Delete"
                                OnClientClick='JavaScript:return confirm("Are you sure?");' CommandArgument='<%# DataBinder.Eval(Container, "DataItem.ID") %>'></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <EmptyDataTemplate>
                    No records found</EmptyDataTemplate>
                <PagerTemplate>
                    <table width="100%">
                        <tr>
                            <td style="text-align: left; font-size: 11px; width: 100px;">
                                Page
                                <asp:Label ID="lblPageIndex" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1  %>' />
                                of
                                <asp:Label ID="lblPageCount" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount  %>' />
                            </td>
                            <td style="text-align: center; font-size: 11px;">
                                <asp:Panel ID="pnlPager" runat="server" DefaultButton="lnkGo">
                                    <asp:LinkButton ID="lnkFirst" runat="server" CausesValidation="False" CommandArgument="First"
                                        CommandName="Page" Text="Page 1" />&nbsp;&nbsp;
                                    <asp:LinkButton ID="lnkPrev" runat="server" CausesValidation="False" CommandArgument="Prev"
                                        CommandName="Page" Text="<< Prev" />&nbsp;&nbsp;
                                    <asp:LinkButton ID="lnkNext" runat="server" CausesValidation="False" CommandArgument="Next"
                                        CommandName="Page" Text="Next >>" />&nbsp;&nbsp;
                                    <asp:LinkButton ID="lnkLast" runat="server" CausesValidation="False" CommandArgument="Last"
                                        CommandName="Page" Text='<%# "Page "+ ((GridView)Container.Parent.Parent).PageCount  %>' />&nbsp;&nbsp;&nbsp;
                                    <asp:TextBox ID="txtNewPageIndex" runat="server" Width="20px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1  %>' />
                                    <asp:LinkButton ID="lnkGo" runat="server" CausesValidation="False" CommandArgument="-1"
                                        CommandName="Page" Text="Go" /><!-- here set the CommandArgument of the Go Button to '-1' as the flag -->
                                </asp:Panel>
                            </td>
                        </tr>
                    </table>
                </PagerTemplate>
            </asp:GridView>
        </ContentTemplate>
    </clib:UpdatePanelExtender>
</asp:Content>
